7f66be
@@ -26,6 +26,7 @@
import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -202,6 +203,9 @@
public class XMLConfiguration extends AbstractHierarchicalFileConfiguration
     /** Stores a flag whether DTD validation should be performed.*/
     private boolean validating;
 
+    /** A flag whether attribute splitting is disabled.*/
+    private boolean attributeSplittingDisabled;
+
     /**
      * Creates a new instance of <code>XMLConfiguration</code>.
      */
@@ -410,6 +414,71 @@
public class XMLConfiguration extends AbstractHierarchicalFileConfiguration
         this.validating = validating;
     }
 
+    /**
+     * Returns the flag whether attribute splitting is disabled.
+     *
+     * @return the flag whether attribute splitting is disabled
+     * @see #setAttributeSplittingDisabled(boolean)
+     * @since 1.6
+     */
+    public boolean isAttributeSplittingDisabled()
+    {
+        return attributeSplittingDisabled;
+    }
+
+    /**
+     * <p>
+     * Sets a flag whether attribute splitting is disabled.
+     * </p>
+     * <p>
+     * The Configuration API allows adding multiple values to an attribute. This
+     * is problematic when storing the configuration because in XML an attribute
+     * can appear only once with a single value. To solve this problem, per
+     * default multiple attribute values are concatenated using a special
+     * separator character and split again when the configuration is loaded. The
+     * separator character is either the list delimiter character (see
+     * {@link #setListDelimiter(char)}) or the pipe symbol (&quot;|&quot;) if
+     * list delimiter parsing is disabled.
+     * </p>
+     * <p>
+     * In some constellations the splitting of attribute values can have
+     * undesired effects, especially if list delimiter parsing is disabled and
+     * attributes may contain the &quot;|&quot; character. In these cases it is
+     * possible to disable the attribute splitting mechanism by calling this
+     * method with a boolean value set to <b>false</b>. If attribute splitting
+     * is disabled, the values of attributes will not be processed, but stored
+     * as configuration properties exactly as they are returned by the XML
+     * parser.
+     * </p>
+     * <p>
+     * Note that in this mode multiple attribute values cannot be handled
+     * correctly. It is possible to create a <code>XMLConfiguration</code>
+     * object, add multiple values to an attribute and save it. When the
+     * configuration is loaded again and attribute splitting is disabled, the
+     * attribute will only have a single value, which is the concatenation of
+     * all values set before. So it lies in the responsibility of the
+     * application to carefully set the values of attributes.
+     * </p>
+     * <p>
+     * As is true for the {@link #setDelimiterParsingDisabled(boolean)} method,
+     * this method must be called before the configuration is loaded. So it
+     * can't be used together with one of the constructors expecting the
+     * specification of the file to load. Instead the default constructor has to
+     * be used, then <code>setAttributeSplittingDisabled(false)</code> has to be
+     * called, and finally the configuration can be loaded using one of its
+     * <code>load()</code> methods.
+     * </p>
+     *
+     * @param attributeSplittingDisabled <b>true</b> for disabling attribute
+     *        splitting, <b>false</b> for enabling it
+     * @see #setDelimiterParsingDisabled(boolean)
+     * @since 1.6
+     */
+    public void setAttributeSplittingDisabled(boolean attributeSplittingDisabled)
+    {
+        this.attributeSplittingDisabled = attributeSplittingDisabled;
+    }
+
     /**
      * Returns the XML document this configuration was loaded from. The return
      * value is <b>null</b> if this configuration was not loaded from a XML
@@ -517,14 +586,22 @@
public class XMLConfiguration extends AbstractHierarchicalFileConfiguration
             if (w3cNode instanceof Attr)
             {
                 Attr attr = (Attr) w3cNode;
-                Iterator it = PropertyConverter.split(
-                        attr.getValue(),
-                        isDelimiterParsingDisabled() ? ATTR_VALUE_DELIMITER
-                                : getListDelimiter()).iterator();
-                while (it.hasNext())
+                List values;
+                if (isAttributeSplittingDisabled())
+                {
+                    values = Collections.singletonList(attr.getValue());
+                }
+                else
+                {
+                    values = PropertyConverter.split(attr.getValue(),
+                            isDelimiterParsingDisabled() ? ATTR_VALUE_DELIMITER
+                                    : getListDelimiter());
+                }
+
+                for (Iterator it = values.iterator(); it.hasNext();)
                 {
-                    Node child = new XMLNode(attr.getName(),
-                            elemRefs ? element : null);
+                    Node child = new XMLNode(attr.getName(), elemRefs ? element
+                            : null);
                     child.setValue(it.next());
                     node.addAttribute(child);
                 }
